using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Utility;
using Entities;
using BUS;
using DAL;

public partial class admin_Chitietdonhang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }

    }
    private void LoadData()
    {
        try
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            tbDonHang donhang = tbDonHangBUS.GetByID(id);
            lit_MaDonHang.Text = donhang.MaDH .ToString();
            tbKhachHang khachhang = tbKhachHangBUS.GetByID(donhang.MaKH );
            lit_KhachHang.Text = khachhang.TenKH;
            lit_NgayDatHang.Text = donhang.NgayDatHang .ToString();
            lit_NgayGiaoHang.Text = donhang.NgayGiaoHang .ToString();
            lit_TriGia.Text = donhang.Trigia .ToString();
            lit_diachinhanhang .Text = donhang.Diachigiaohang .ToString();
            Lit_Hinhthuctt .Text = donhang.HinhThucTT .ToString();
            lit_Trangthai.Text = donhang.TrangThai.ToString();
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbCTDonHangColumns.SoDH , Condition.EQUAL, donhang.MaDH );
            //hyperlinkPager.PageSize = int.Parse(ConfigurationManager.AppSettings["pagesize"]);
            tbCTDonHangCollection cTDonhangCollection = tbCTDonHangBUS.Get(cri.Criter, hyperlinkPager.CurrentIndex, hyperlinkPager.PageSize, tbCTDonHangColumns.MaCTHD .ToString(), OrderDirection.ASC.ToString(), out total);
            Repeater1.DataSource = cTDonhangCollection;
            Repeater1.DataBind();
            hyperlinkPager.ItemCount = total;
            if (hyperlinkPager.ItemCount <= hyperlinkPager.PageSize)
                hyperlinkPager.Visible = false;
            else
                hyperlinkPager.Visible = true;
        }
        catch
        {
            Response.Redirect("~/Admin/Danhsachdonhang.aspx");
        }


    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.AlternatingItem ||
        e.Item.ItemType == ListItemType.Item)
        {

            tbCTDonHang cTDonhang = (tbCTDonHang)e.Item.DataItem;
            tbSanPham sanpham = tbSanPhamBUS.GetByID(cTDonhang.MaSP );
            if (sanpham != null)
            {

                Literal lit_Tensp = (Literal)e.Item.FindControl("lit_Tensp");
                lit_Tensp.Text = sanpham.TenSP;
            }

            Literal lit_ThanhTien = (Literal)e.Item.FindControl("lit_ThanhTien");
            int tongTien = cTDonhang.Soluong  * cTDonhang.GiaBan ;
            lit_ThanhTien.Text = tongTien.ToString();
        }
    }

    protected void hyperlinkPager_Command(object sender, CommandEventArgs e)
    {
        hyperlinkPager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
}
